package com.feature.learn.lambda.stream;

import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.stream.Stream;

/**
 * 注意：
 * java version "1.8.0_25"
 * Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
 * Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
 * 这个版本下会出现这个问题
 * Information:java: 编译器 (1.8.0_25) 中出现异常错误。 如果在 Bug Parade 中没有找到该错误, 请在 Java Developer Connection (http://java.sun.com/webapps/bugreport) 中建立 Bug。请在报告中附上您的程序和以下诊断信息。谢谢。
 * Information:java: java.lang.NullPointerException
 * Information:java: 	at com.sun.tools.javac.code.Types.isConvertible(Types.java:290)
 * Information:java: 	at com.sun.tools.javac.comp.Check.assertConvertible(Check.java:922)
 * Information:java: 	at com.sun.tools.javac.comp.Check.checkMethod(Check.java:876)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3838)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3615)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3522)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3501)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3488)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3370)
 * Information:java: 	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
 * Information:java: 	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:649)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1093)
 * Information:java: 	at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
 * Information:java: 	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
 * Information:java: 	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
 * Information:java: 	at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
 * Information:java: 	at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
 * Information:java: 	at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
 * Information:java: 	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
 * Information:java: 	at com.sun.tools.javac.main.Main.compile(Main.java:523)
 * Information:java: 	at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
 * Information:java: 	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
 * Information:java: 	at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:206)
 * Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:460)
 * Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:330)
 * Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:255)
 * Information:java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:213)
 * Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1324)
 * Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1004)
 * Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1071)
 * Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:965)
 * Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:794)
 * Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:376)
 * Information:java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:178)
 * Information:java: 	at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:139)
 * Information:java: 	at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:288)
 * Information:java: 	at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:121)
 * Information:java: 	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:228)
 * Information:java: 	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$$Lambda$54/732171990.run(Unknown Source)
 * Information:java: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 * Information:java: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 * Information:java: 	at java.lang.Thread.run(Thread.java:745)
 * Information:java: Errors occurred while compiling module 'feature-learning'
 * Information:javac 1.8.0_25 was used to compile java sources
 * Information:2019/12/31 9:48 - Build completed with 1 error and 0 warnings in 1 s 294 ms
 * Error:java: Compilation failed: internal java compiler error
 *
 * @author wangxc
 * @date: 2019-08-17 19:40
 */
public class ReduceExample33 {
    public static void main(String[] args) {
//        int i = Stream.of("2", "3", "4", "5") // 此种写法会引发如上的问题
//                .parallel()
//                .reduce(0, (integer, s) -> Integer.sum(integer, Integer.parseInt(s)),
//                        Integer::sum);


        Integer reduce = Stream.of("2", "3", "4", "5").reduce(0, (integer, s) -> {
            Integer integer1 = Integer.valueOf(s);
            return integer + integer1;
        }, (integer, integer2) -> integer + integer2);
        System.out.println(reduce);
    }
}
